package cn.shop.dys.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.bean.AllIndentItem;
import cn.shop.dys.bean.CartItem;
import cn.shop.dys.bean.MyCheckoutAddup;
import cn.shop.dys.bean.OrderInfo;
import cn.shop.dys.bean.ProductInfo;
import cn.shop.dys.bean.ProductProperty;
import cn.shop.dys.constant.CommonConstant;
import cn.shop.dys.constant.SPConstant;
import cn.shop.dys.util.SPUtil;
import cn.shop.dys.widget.SingleIndentItem;
import cn.shop.lib_common.CommonUtil;
import cn.shop.lib_common.CommonViewHolder;

/**
 * 作者：jian on 2016/4/22 17:20
 * 孙建
 */
public abstract class IndentBaseAdapter extends BaseAdapter{
    public void cancelOrderInfo(AllIndentItem allIndentItem, HttpUtils mHttpUtils, final Context mContext) {
        mHttpUtils.configDefaultHttpCacheExpiry(0);
        mHttpUtils.configTimeout(10000);
        RequestParams params = new RequestParams();
    //    Log.d("test","userid"+allIndentItem.getmOrderInfo().getOrderId());
        params.addHeader("userid", SPUtil.getString(mContext, SPConstant.USER_INFO_USER_ID));
        params.addBodyParameter("orderId", allIndentItem.getmOrderInfo().getOrderId());
        mHttpUtils.send(HttpRequest.HttpMethod.POST, CommonConstant.HOST_ORDER_CANCEL, params,
                new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        int statusCode = responseInfo.statusCode;
                        if (statusCode == 200) {
                            String result = responseInfo.result;
                            try {
                                JSONObject jsonObject = new JSONObject(result);
                                String response = jsonObject.getString("response");
                                if (response.equals("orderCancel")) {
                                    CommonUtil.showToast(mContext, "取消订单成功");
                                } else {
                                    String error = jsonObject.getString("error");
                                    String error_code = jsonObject.getString(CommonConstant.ERROR_CODE);
                                    if (error_code.equals(CommonConstant.ERROR_CODE_NO_USERID_ON_REQUEST_HEAD)) {
                                        CommonUtil.showToast(mContext, error);
                                    } else if (error_code.equals(CommonConstant.ERROR_CODE_UNLOGIN)) {
                                        CommonUtil.showToast(mContext, error);
                                    }else if (error_code.equals(CommonConstant.ERROR_CODE_FAILER_CANCLE_ORDER)) {
                                        CommonUtil.showToast(mContext, error);
                                    }
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            CommonUtil.showToast(mContext, "请求失败:错误码为" + statusCode);
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        CommonUtil.showToast(mContext, "网络未连接2" + msg);
                    }

                });
    }

}
